uniform sampler2D Sampler;
uniform mat3 normalMatrix;		//Normal Matrix, ie Inv-Transpose of ModelView Matrix

varying vec3 vUVOut;
varying vec3 eyeSpaceNormal;
varying vec3 objectNormal;
varying vec3 lightDir;

void main(void)
{			
		if(vUVOut.z > 0)//Check to see if the vertex was front facing or back facing in generated normalMap
		{
			vec3 N = normalMatrix * normalize(texture2D(Sampler, vUVOut).xyz * 2.0 - 1.0);//Generate Preturbed normal (0 to 1 --> -1 to 1)
			vec3 L = normalize(lightDir);
			float diffuse = max( 0.0, dot(N,L) );	
		
		  gl_FragColor =  vec4(diffuse, diffuse, diffuse, 1.0);	  //shows normalmap as normals
		  //gl_FragColor =  vec4(texture2D(Sampler, vUVOut).xyz, 1.0);//Shows normalmap as color
		}
		else
		{//We don't have normalmap data for this vertex, render using vertex normals
		//(This portion should be high res geometry)
			vec3 N = normalize(eyeSpaceNormal);		
			vec3 L = normalize(lightDir);
			float diffuse = max( 0.0, dot(N,L) );	
			gl_FragColor =  vec4(diffuse, diffuse, diffuse, 1.0);
		}
		//gl_FragColor = vec4(vUVOut.x, vUVOut.y,0.0,1.0);
	
}

